-module(invoice).

-include_lib("eunit/include/eunit.hrl").

-define(FILENAME, "test/examples/" ?MODULE_STRING ".yaml").

setup() ->
    application:start(yamerl).

simple_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            [
              {"invoice",34843},
              {"date","2001-01-23"},
              {"bill-to",
                [
                  {"given","Chris"},
                  {"family","Dumars"},
                  {"address",
                    [
                      {"lines","458 Walkman Dr.\nSuite #292\n"},
                      {"city","Royal Oak"},
                      {"state","MI"},
                      {"postal",48046}]}]},
              {"ship-to",
                [
                  {"given","Chris"},
                  {"family","Dumars"},
                  {"address",
                    [
                      {"lines","458 Walkman Dr.\nSuite #292\n"},
                      {"city","Royal Oak"},
                      {"state","MI"},
                      {"postal",48046}]}]},
              {"product",
                [
                  [
                    {"sku","BL394D"},
                    {"quantity",4},
                    {"description","Basketball"},
                    {"price",450.0}],
                  [
                    {"sku","BL4438H"},
                    {"quantity",1},
                    {"description","Super Hoop"},
                    {"price",2392.0}]]},
              {"tax",251.42},
              {"total",4443.52},
              {"comments",
                "Late afternoon is best. "
                "Backup contact is Nancy Billsmer @ 338-4338."}]
          ],
          yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
        )
      ]
    }.

detailed_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            {yamerl_doc,{yamerl_map,yamerl_node_map,
                "tag:yaml.org,2002:map",
                [{line,2},{column,1}],
                [
                  {
                    {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                      [{line,2},{column,1}],
                      "invoice"},
                    {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                      [{line,2},{column,10}],
                      34843}},
                  {
                    {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                      [{line,3},{column,1}],
                      "date"},
                    {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                      [{line,3},{column,10}],
                      "2001-01-23"}},
                  {
                    {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                      [{line,4},{column,1}],
                      "bill-to"},
                    {yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
                      [{line,5},{column,5}],
                      [
                        {
                          {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                            [{line,5},{column,5}],
                            "given"},
                          {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                            [{line,5},{column,14}],
                            "Chris"}},
                        {
                          {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                            [{line,6},{column,5}],
                            "family"},
                          {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                            [{line,6},{column,14}],
                            "Dumars"}},
                        {
                          {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                            [{line,7},{column,5}],
                            "address"},
                          {yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
                            [{line,8},{column,9}],
                            [
                              {
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,8},{column,9}],
                                  "lines"},
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,8},{column,16}],
                                  "458 Walkman Dr.\nSuite #292\n"}},
                              {
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,11},{column,9}],
                                  "city"},
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,11},{column,19}],
                                  "Royal Oak"}},
                              {
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,12},{column,9}],
                                  "state"},
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,12},{column,19}],
                                  "MI"}},
                              {
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,13},{column,9}],
                                  "postal"},
                                {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                                  [{line,13},{column,19}],
                                  48046}}]}}]}},
                  {
                    {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                      [{line,14},{column,1}],
                      "ship-to"},
                    {yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
                      [{line,5},{column,5}],
                      [
                        {
                          {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                            [{line,5},{column,5}],
                            "given"},
                          {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                            [{line,5},{column,14}],
                            "Chris"}},
                        {
                          {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                            [{line,6},{column,5}],
                            "family"},
                          {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                            [{line,6},{column,14}],
                            "Dumars"}},
                        {
                          {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                            [{line,7},{column,5}],
                            "address"},
                          {yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
                            [{line,8},{column,9}],
                            [
                              {
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,8},{column,9}],
                                  "lines"},
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,8},{column,16}],
                                  "458 Walkman Dr.\nSuite #292\n"}},
                              {
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,11},{column,9}],
                                  "city"},
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,11},{column,19}],
                                  "Royal Oak"}},
                              {
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,12},{column,9}],
                                  "state"},
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,12},{column,19}],
                                  "MI"}},
                              {
                                {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                  [{line,13},{column,9}],
                                  "postal"},
                                {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                                  [{line,13},{column,19}],
                                  48046}}]}}]}},
                  {
                    {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                      [{line,15},{column,1}],
                      "product"},
                    {yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
                      [{line,16},{column,5}],
                      [
                        {yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
                          [{line,16},{column,7}],
                          [
                            {
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,16},{column,7}],
                                "sku"},
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,16},{column,21}],
                                "BL394D"}},
                            {
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,17},{column,7}],
                                "quantity"},
                              {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                                [{line,17},{column,21}],
                                4}},
                            {
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,18},{column,7}],
                                "description"},
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,18},{column,21}],
                                "Basketball"}},
                            {
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,19},{column,7}],
                                "price"},
                              {yamerl_float,yamerl_node_float,
                                "tag:yaml.org,2002:float",
                                [{line,19},{column,21}],
                                450.0}}]},
                        {yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
                          [{line,20},{column,7}],
                          [
                            {
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,20},{column,7}],
                                "sku"},
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,20},{column,21}],
                                "BL4438H"}},
                            {
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,21},{column,7}],
                                "quantity"},
                              {yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
                                [{line,21},{column,21}],
                                1}},
                            {
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,22},{column,7}],
                                "description"},
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,22},{column,21}],
                                "Super Hoop"}},
                            {
                              {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                                [{line,23},{column,7}],
                                "price"},
                              {yamerl_float,yamerl_node_float,
                                "tag:yaml.org,2002:float",
                                [{line,23},{column,21}],
                                2392.0}}]}],
                      2}},
                  {
                    {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                      [{line,24},{column,1}],
                      "tax"},
                    {yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
                      [{line,24},{column,8}],
                      251.42}},
                  {
                    {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                      [{line,25},{column,1}],
                      "total"},
                    {yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
                      [{line,25},{column,8}],
                      4443.52}},
                  {
                    {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                      [{line,26},{column,1}],
                      "comments"},
                    {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                      [{line,27},{column,5}],
                      "Late afternoon is best. "
                      "Backup contact is Nancy Billsmer @ 338-4338."}}]}}
          ],
          yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
        )
      ]
    }.
